package com.cmcc.groupcontacts.firewall.activity.strategy;

import android.graphics.Color;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cmcc.groupcontacts.firewall.activity.BaseActivity;
import com.yinhai.activity.R;

/**
 * 标题栏存在的显示策略抽象基类
 * 
 * @author
 * 
 */
public abstract class BaseHasTitleStrategy extends BaseTitleStrategy {
	protected RelativeLayout customLayout; // 标题栏布局
	protected TextView customTitle; // 标题栏文本
	protected LinearLayout leftLayout; // 标题栏左边布局
	protected LinearLayout centerLayout; // 标题栏中间布局
	protected LinearLayout rightLayout; // 标题栏右边布局

	public BaseHasTitleStrategy(BaseActivity act) {
		super(act);
	}

	@Override
	public RelativeLayout getTitleLayout() {
		if (customLayout == null) {
			customLayout = (RelativeLayout) act
					.findViewById(R.id.custom_layout);
		}
		return customLayout;
	}

	@Override
	public TextView getTitleTextView() {
		if (customTitle == null) {
			customTitle = (TextView) act.findViewById(R.id.custom_title);
		}
		return customTitle;
	}

	@Override
	public LinearLayout getLeftLayout() {
		if (leftLayout == null) {
			leftLayout = (LinearLayout) act
					.findViewById(R.id.custom_left_layout);
		}
		return leftLayout;
	}

	@Override
	public LinearLayout getCenterLayout() {
		if (centerLayout == null) {
			centerLayout = (LinearLayout) act
					.findViewById(R.id.custom_center_layout);
		}
		return centerLayout;
	}

	@Override
	public LinearLayout getRightLayout() {
		if (rightLayout == null) {
			rightLayout = (LinearLayout) act
					.findViewById(R.id.custom_right_layout);
		}
		return rightLayout;
	}

	@Override
	public ImageButton createImageButton() {
		ImageButton imgBtn = new ImageButton(act);
		imgBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));
		imgBtn.setPadding(0, 0, 0, 0);
		imgBtn.setBackgroundDrawable(null);
		return imgBtn;
	}

	@Override
	public Button createButton() {
		Button btn = new Button(act);
		btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));
		btn.setPadding(0, 0, 0, 0);
		btn.setBackgroundDrawable(null);
		return btn;
	}

	@Override
	public void setTitleText() {
		if (getTitleTextView() != null) {
			getTitleTextView().setText(act.getTitle());
		}
	}

	@Override
	public void setTitleSkin() {
		if (getTitleLayout() != null) {
			// getTitleLayout().setBackgroundDrawable(act.getDrawable(R.drawable.top_bg));
			getTitleLayout().setBackgroundColor(Color.parseColor("#F0F4F0"));

			if (getTitleTextView() != null) {
				// getTitleTextView().setTextColor(
				// act.getColor(R.color.text_header_title));
				// #111111
				getTitleTextView().setTextColor(Color.parseColor("#111111"));
			}
		}
	}
}
